package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AddItemActivity extends AppCompatActivity {

    EditText editText3;
    EditText editText4;
    EditText editText5;
    EditText editText6;
    EditText editText7;
    EditText editText8;
    Button button3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_item);

        editText3 = findViewById(R.id.editText3);
        editText4 = findViewById(R.id.editText4);
        editText5 = findViewById(R.id.editText5);
        editText6 = findViewById(R.id.editText6);
        editText7 = findViewById(R.id.editText7);
        editText8 = findViewById(R.id.editText8);
        button3=findViewById(R.id.button3);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//获取数据
                String name = editText3.getText().toString();
                String desc = editText4.getText().toString();
                String remark = editText5.getText().toString();
                String price = editText6.getText().toString();
                String kindId = editText7.getText().toString();
                String avail = editText8.getText().toString();
//打包数据
                Map<String,String> map = new HashMap<>();
                map.put("itemName",name);
                map.put("itemDesc",desc);
                map.put("itemRemark",remark);
                map.put("initPrice",price);
                map.put("kindId",kindId);
                map.put("avail",avail);
//                发送数据
                try {
                    String result=OkHttpUtil.postRequest("http://172.18.85.254:8080/auction/api/items",map);
                    Toast.makeText(AddItemActivity.this,result,Toast.LENGTH_LONG).show();

                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
    }
//            @Override
//           public void onClick(View view){
//                switch (view.getId()){
//            case R.id.button3:
//
//                break;
//            }
//            }
}
